﻿using System;
using SharpKit.JavaScript;

namespace SharpKit.Onx
{
    /// <summary>
    /// Battery state collector
    /// https://www.onx.ms/#apiPage/battery
    /// </summary>
    [JsType(Mode = JsMode.Prototype, Export = false)]
    public class Battery : Emitter
    {
        //No way to new this up
        private Battery()
        { }

        #region Properties
        /// <summary>
        /// Returns the current battery status.
        /// </summary>
        [JsProperty(Name = "status", NativeField = true)]
        public BatterySignal Status { get { return null; } }
        #endregion

        #region Triggers (Events)
        /// <summary>
        /// trigger is received when battery power is high. Additional trigger data is available in the BatterySignal parameter passed to the callback function.
        /// </summary>
        public event Action<BatterySignal> High
        {
            [JsMethod(Name = "on", InsertArg0 = "'high'")]
            add
            {
            }
            [JsMethod(Name = "removeListener", InsertArg0 = "'high'")]
            remove
            {
            }
        }

        /// <summary>
        /// trigger is received when battery power is low. Additional trigger data is available in the BatterySignal parameter passed to the callback function.
        /// </summary>
        public event Action<BatterySignal> Low
        {
            [JsMethod(Name = "on", InsertArg0 = "'low'")]
            add
            {
            }
            [JsMethod(Name = "removeListener", InsertArg0 = "'low'")]
            remove
            {
            }
        }

        /// <summary>
        /// trigger is received when the battery begins charging. Additional trigger data is available in the BatterySignal parameter passed to the callback function.
        /// </summary>
        public event Action<BatterySignal> StartedCharging
        {
            [JsMethod(Name = "on", InsertArg0 = "'startedCharging'")]
            add
            {
            }
            [JsMethod(Name = "removeListener", InsertArg0 = "'startedCharging'")]
            remove
            {
            }
        }

        /// <summary>
        /// trigger is received when the battery stops charging. Additional trigger data is available in the BatterySignal parameter passed to the callback function.
        /// </summary>
        public event Action<BatterySignal> StoppedCharging
        {
            [JsMethod(Name = "on", InsertArg0 = "'stoppedCharging'")]
            add
            {
            }
            [JsMethod(Name = "removeListener", InsertArg0 = "'stoppedCharging'")]
            remove
            {
            }
        }

        /// <summary>
        /// trigger is received when battery's status or charge level changes. Additional trigger data is available in the BatterySignal parameter passed to the callback function.
        /// </summary>
        public event Action<BatterySignal> Updated
        {
            [JsMethod(Name = "on", InsertArg0 = "'updated'")]
            add
            {
            }
            [JsMethod(Name = "removeListener", InsertArg0 = "'updated'")]
            remove
            {
            }
        }
        #endregion
    }

    /// <summary>
    /// Holds the state of the battery (percentage, charging). Will be triggered on changes in battery state.
    /// </summary>
    [JsType(Mode = JsMode.Json, Export = false)]
    public class BatterySignal : ScriptSignal
    {
        /// <summary>
        /// Checks whether a charger was connected when the signal was collected.
        /// </summary>
        [JsProperty(Name = "isCharging", NativeField = true)]
        public bool IsCharging { get { return false; } }

        /// <summary>
        /// 
        /// </summary>
        [JsProperty(Name = "precentage", NativeField = true)]
        public JsNumber Precentage { get { return null; } }

        /// <summary>
        /// 
        /// </summary>
        [JsProperty(Name = "isLow", NativeField = true)]
        public JsNumber IsLow { get { return null; } }

        /// <summary>
        /// 
        /// </summary>
        [JsProperty(Name = "isHigh", NativeField = true)]
        public JsNumber IsHigh { get { return null; } }
    }
}